<template>
<table>
    <tr>
        <td>用户名</td>
        <td><input type="text" name="username" v-model="data.Uname"></td>
    </tr>
    <tr>
        <td>密码</td>
        <td><input type="password" name="password" v-model="data.Upwd"></td>
    </tr>
    <tr>
        <td colspan="2"><input type="button" value="登录" @click="Ulogin"></td>
    </tr>
</table>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import axios from 'axios';
import {useRouter} from 'vue-router';
const router=useRouter();
const data=ref(
    {
        Uname:'',
        Upwd:''
    }
)


const Ulogin=()=>{
    axios.post('https://localhost:44323/api/Lx/Ulogin',
        {
            
            Uname:data.value.Uname,
            Upwd:data.value.Upwd
        }
    ).then(res=>{
        if(res.data==1){
            alert("用户已经登录")
            router.push(
                {
                    name:"Infor",
                    params:{
                        Uname:data.value.Uname,
                    }
                }
            )
        }
        else if(res.data==-1){
            alert("用户名密码错误")
        }else{
            alert("登录成功")
        }
    }).catch(err=>{
        console.log(err);
    })
}

</script>